//
//  CategoryEditViewController.m
//  SAYAKA_Table
//
//  Created by numanuma08 on 2013/07/20.
//  Copyright (c) 2013年 勘米良. All rights reserved.
//

#import "CategoryEditViewController.h"
#import "NSString+IsEmpty.h"
#import "Category.h"
@interface CategoryEditViewController ()
@property (strong, nonatomic) IBOutlet UIButton *edtImageButton;
@property (strong, nonatomic) IBOutlet UITextField *editNameField;

@end

@implementation CategoryEditViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = _category.name;
    _editNameField.placeholder = _category.name;
    
    if (![_category.background_image_path isEmpty]) {
        UIImage* categoryBackground = [UIImage imageNamed:_category.background_image_path];
        [_edtImageButton setBackgroundImage:categoryBackground forState:UIControlStateNormal];
        _edtImageButton.titleLabel.text = @"";
    }
}
- (IBAction)selectCancelButton:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
        [_parent didCancelEdit:self];
    }];
}

- (IBAction)selectEditComplete:(id)sender
{
    //TODO Edit category
    if([_editNameField.text isEmpty]){
        [self dismissViewControllerAnimated:YES completion:^{
            [_parent didCancelEdit:self];
        }];
        return;
    }

    _category.name = _editNameField.text;
    [self dismissViewControllerAnimated:YES completion:^{
        [_parent category:_category didCompleteEdit:self];
    }];
}

- (IBAction)selectEditImage:(id)sender
{
}
@end
